#include "Link.h"
// 单链表的创建
Link_list *init_link_list()
{
  Link_list *list = (Link_list *)malloc(sizeof(Link_list));
  if (list == NULL)
  {
    printf("链表创建失败\n");
    return NULL;
  }
  list->next = NULL;
  return list;
}
// 单链表的尾插入
void tail_insert(Link_list *list, Element_data data)
{
  Node *p = (Node *)malloc(sizeof(Node));
  if (p == NULL)
  {
    printf("创建结点失败\n");
    return;
  }
  if (list->next == NULL)
  {
    list->next = p;
    p->data = data;
    p->next = NULL;
    return;
  }
  p = list->next;
  for (int i = 0; p->next != NULL; i++)
  {
    p = p->next;
  }
  Node *q = (Node *)malloc(sizeof(Node));
  p->next = q;
  q->data = data;
  q->next = NULL;
}
// 单链表的遍历
void print_link_list(Link_list *list)
{
  if (list->next == NULL)
  {
    printf("该链表是空表\n");
  }
  Node *ptr = list->next;
  for (size_t i = 0; ptr != NULL; i++)
  {

    printf("姓名:%s 性别:%s 年龄:%d 成绩:%d 学号:%d\n",
           ptr->data.name, ptr->data.sex, ptr->data.age,
           ptr->data.sco, ptr->data.id);
    ptr = ptr->next;
  }
}
// 链表的尾删
void tail_dele(Link_list *list)
{
  Node *p = (Node *)malloc(sizeof(Node));
  p = list->next;
  if (list->next == NULL)
  {
    printf("链表为空\n");
  }
  for (size_t i = 0; p->next->next != NULL; i++)
  {
    p = p->next;
  }
  free(p->next);
  p->next = NULL;
}